﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import com.greensock.*;

    public class ScrollingImageObject extends Sprite {

        protected static const TWEEN_TIME:Number = 0.5;

        protected var m_items:Array;
        protected var m_sprites:Array;
        protected var m_timer:Timer;
        protected var m_totalLoaded:int = 0;
        protected var m_curItem:int = 0;
        protected var m_width:int;
        protected var m_height:int;
        protected var m_bg:String;

        public function ScrollingImageObject(_arg1:Array, _arg2:int, _arg3:int, _arg4:String=""){
            this.m_sprites = new Array();
            this.m_timer = new Timer(2000);
            this.m_width = _arg2;
            this.m_height = _arg3;
            this.m_bg = _arg4;
            this.m_items = _arg1;
            super();
            this.init();
        }
        protected function init():void{
            var _local2:Loader;
            if (this.m_bg != ""){
                LoadingManager.load(Global.getAssetURL(this.m_bg), this.addBG);
            };
            this.m_timer.addEventListener(TimerEvent.TIMER, this.shiftItems, false, 0, true);
            var _local1:int;
            while (_local1 < this.m_items.length) {
                _local2 = LoadingManager.load(this.m_items[_local1], this.loadItems);
                _local1++;
            };
        }
        protected function addBG(_arg1:Event):void{
            var _local2:DisplayObject = _arg1.target.content;
            _local2.x = ((this.m_width - _local2.width) / 2);
            _local2.y = ((this.m_height - _local2.height) / 2);
            addChildAt(_local2, 0);
        }
        protected function loadItems(_arg1:Event):void{
            var _local2:Sprite = new Sprite();
            var _local3:DisplayObject = _arg1.target.content;
            _local2.addChild(_local3);
            _local3.x = ((this.m_width - _local3.width) / 2);
            _local3.y = ((this.m_height - _local3.height) / 2);
            this.m_sprites.push(_local2);
            this.m_totalLoaded++;
            if (this.m_totalLoaded == this.m_items.length){
                this.setupItems();
            };
        }
        public function setupItems():void{
            var _local1:int;
            while (_local1 < this.m_sprites.length) {
                if (_local1 != 0){
                    this.m_sprites[_local1].x = this.m_width;
                    this.m_sprites[_local1].alpha = 0;
                };
                addChild(this.m_sprites[_local1]);
                _local1++;
            };
            this.m_timer.start();
        }
        protected function shiftItems(_arg1:TimerEvent):void{
            var nextItem:* = 0;
            var e:* = _arg1;
            nextItem = (this.m_curItem + 1);
            if (nextItem >= this.m_sprites.length){
                nextItem = 0;
            };
            var curItem:* = this.m_curItem;
            var prevItem:* = (this.m_curItem - 1);
            if (prevItem < 0){
                prevItem = (this.m_sprites.length - 1);
            };
            this.m_sprites[nextItem].x = this.m_width;
            TweenLite.to(this.m_sprites[curItem], TWEEN_TIME, {
                x:-(this.m_width),
                alpha:0
            });
            this.m_sprites[curItem];
            TweenLite.to(this.m_sprites[nextItem], TWEEN_TIME, {
                x:0,
                alpha:1,
                onComplete:function ():void{
                    m_curItem = nextItem;
                }
            });
        }

    }
}//package Display 
